package com.example.myuniversity;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationSet;
import android.view.animation.BounceInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.OnChildClickListener;

public class MajorPkActivity extends Activity {
	private TextView txtFirstOne,txtFirstTwo,txtSecondOne,
	txtSecondTwo,txtThirdOne,txtThirdTwo,txtFourthOne,txtFourthTwo,txtFifthOne,txtFifthTwo;
	private LinearLayout layoutFirst,layoutSecond,layoutThird,layoutFourth,layoutFifth;
	private ImageView imagePkCenter,imageFinish;
	private TranslateAnimation animation;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pk);
		init();
		setOnClick();
		MediaPlayer mp=MediaPlayer.create(MajorPkActivity.this, R.raw.music);
		if (mp!=null) {
			mp.stop();
		}
		try {
			mp.prepare();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		mp.start();
		
		
	}

	private void init() {
		
		imageFinish=(ImageView) findViewById(R.id.image_majorpk_finish);
		imagePkCenter=(ImageView) findViewById(R.id.image_pa_center);
		
		layoutFirst=(LinearLayout) findViewById(R.id.layout_pk_first);
		layoutSecond=(LinearLayout) findViewById(R.id.layout_pk_second);
		layoutThird=(LinearLayout) findViewById(R.id.layout_pk_third);
		layoutFourth=(LinearLayout) findViewById(R.id.layout_pk_fourth);
		layoutFifth=(LinearLayout) findViewById(R.id.layout_pk_fifth);
	
		
		txtFirstOne=(TextView) findViewById(R.id.txt_pk_first_one);
		txtFirstTwo=(TextView) findViewById(R.id.txt_pk_first_two);
		txtSecondOne=(TextView) findViewById(R.id.txt_second_one);
		txtSecondTwo=(TextView) findViewById(R.id.txt_second_two);
		txtThirdOne=(TextView) findViewById(R.id.txt_third_one);
		txtThirdTwo=(TextView) findViewById(R.id.txt_third_two);
		txtFourthOne=(TextView) findViewById(R.id.txt_fourth_one);
		txtFourthTwo=(TextView) findViewById(R.id.txt_fourth_two);
		txtFifthOne=(TextView) findViewById(R.id.txt_fifth_one);
		txtFifthTwo=(TextView) findViewById(R.id.txt_fifth_two);
		LinearInterpolator lin=new LinearInterpolator();
		//translate设置的值都是相对于本身而言的，以自己的原始坐标为原点
		//第一组
		animation=new TranslateAnimation(-200f, 0f, 0f, 0f);
		animation.setInterpolator(lin);
		animation.setDuration(500);
		txtFirstOne.startAnimation(animation);
		
		animation=new TranslateAnimation(200f, 0f, 0f, 0f);
		animation.setInterpolator(lin);
		animation.setDuration(500);
		txtFirstTwo.startAnimation(animation);
		//第二组
		animation=new TranslateAnimation(-300f, 0f, 0f, 0f);
		animation.setInterpolator(lin);
		animation.setDuration(1000);
		txtSecondOne.startAnimation(animation);
		
		animation=new TranslateAnimation(300f, 0f, 0f, 0f);
		animation.setInterpolator(lin);
		animation.setDuration(1000);
		txtSecondTwo.startAnimation(animation);
		
		
		animation=new TranslateAnimation(-400f, 0f, 0f, 0f);
		animation.setInterpolator(lin);
		animation.setDuration(1500);
		txtThirdOne.startAnimation(animation);
		
		animation=new TranslateAnimation(400f, 0f, 0f, 0f);
		animation.setInterpolator(lin);
		animation.setDuration(1500);
		txtThirdTwo.startAnimation(animation);
		
		
		animation=new TranslateAnimation(-500f, 0f, 0f, 0f);
		animation.setInterpolator(lin);
		animation.setDuration(2000);
		txtFourthOne.startAnimation(animation);
		
		animation=new TranslateAnimation(500f, 0f, 0f, 0f);
		animation.setInterpolator(lin);
		animation.setDuration(2000);
		txtFourthTwo.startAnimation(animation);
		
		
		animation=new TranslateAnimation(-600f, 0f, 0f, 0f);
		animation.setInterpolator(lin);
		animation.setDuration(2500);
		txtFifthOne.startAnimation(animation);
		
		animation=new TranslateAnimation(600f, 0f, 0f, 0f);
		animation.setInterpolator(lin);
		animation.setDuration(2500);
		txtFifthTwo.startAnimation(animation);
		
		BounceInterpolator interpolator=new BounceInterpolator();
		animation=new TranslateAnimation(0f, 0f, -300f, 0f);
		animation.setInterpolator(interpolator);
		animation.setDuration(1000);
		imagePkCenter.startAnimation(animation);
		
	}
	
	private void setOnClick() {
		
		layoutFirst.setOnClickListener(new OnLayoutClickListener());
		layoutSecond.setOnClickListener(new OnLayoutClickListener());
		layoutThird.setOnClickListener(new OnLayoutClickListener());
		layoutFourth.setOnClickListener(new OnLayoutClickListener());
		layoutFifth.setOnClickListener(new OnLayoutClickListener());
		imageFinish.setOnClickListener(new OnLayoutClickListener());
		
	}
	class OnLayoutClickListener implements OnClickListener{
		
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.layout_pk_first:
				
				break;
			case R.id.layout_pk_second:
				
				break;
			case R.id.layout_pk_third:
				
				break;
			case R.id.layout_pk_fourth:
				
				break;
			case R.id.layout_pk_fifth:
				
				break;
			case R.id.image_majorpk_finish:
				finish();
				break;
			default:
				break;
			}
		}
		
	}
	
}
